import R from 'ramda'
import Event from 'events'

export const changeToArr = R.unless(R.is(Array), R.of)

export const convert = middleware => (target, key, descriptor) => {
  let oldValue = descriptor.value
  descriptor.value = R.compose(
    R.concat(changeToArr(middleware)),
    changeToArr
  )(oldValue)
  return descriptor
}

export function sleep(delay = 3000) {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve()
    }, delay)
  })
}

class EventEmitter extends Event {}

export const myEvent =  new EventEmitter()
